//
//  EmojiMemorizeGame.swift
//  Memorize
//
//  Created by 杜森 on 2021/8/19.
//

import SwiftUI

class EmojiMemorizeGame: ObservableObject {
    typealias Card = MemorizeGame<String>.Card
    
    private static let emojis = ["🐳", "🐋", "🐬", "🦭", "🐟", "🐠", "🐡", "🦈", "🐙", "🐚", "🐌", "🦋", "🐛", "🐣", "🐤", "🐥", "🐦", "🐧", "🕊️", "🦅", "🦆", "🦢", "🦉", "🦤", "🪶", "🦩", "🦚", "🦜", "🐸", "🐊", "🐢", "🦎", "🐍", "🐲", "🐉", "🦕", "🦖"]
    
    private static func createMemoryGame() -> MemorizeGame<String> {
        MemorizeGame<String>(numberOfPairsOfCards: 8, createCardContent: {
            pairIndex in EmojiMemorizeGame.emojis[pairIndex]
        })
    }
    
    @Published private var model = EmojiMemorizeGame.createMemoryGame()
    
    var cards: Array<Card> {
        return model.cards
    }
    
    // MARK: - Intent(s)
    // 建议为Intent的方法均设置动画
    
    func choose(_ card: Card){
        model.choose(card)
    }
    
    func shuffle(){
        model.shuffle()
    }
    
    func restart(){
        model = EmojiMemorizeGame.createMemoryGame()
    }
}
